<template>
	<view class="wrap">
		<view class="banner">
			<image src="../../static/zichanbannerbg.png"></image>
			<view class="title">
				总资产
			</view>
			<view class="number">
				{{dataObj.balance}}
			</view>
		</view>
		<view class="tab-wrap">
			<view :class="{'active':nowindex==1}" class="item" @click="tabChange(1)" v-if="!isdata.charge_hidden">
				充值
			</view>
			<view :class="{'active':nowindex==2}" class="item" @click="tabChange(2)" v-if="!isdata.extract_hidden">
				提币
			</view>
		</view>
		<view class="address" v-show="nowindex==2">
			<view class="title">
				提币地址
			</view>
			<view class="ipt-wrap">
				<input v-model="address" type="text" placeholder="输入或长按粘贴地址" />
				<view class="btn" @click="erweima">
					
				</view>
			</view>
			
		</view>
		<view class="address" v-show="nowindex==2">
			<view class="title">
				提币数量   
			</view>
			<view class="ipt-wrap">
				<input v-model="amount" type="text" placeholder="最低转出金额为2" />
				<view class="btn-amount" @click="getAll">
					全部提现
				</view>
			</view>
			
		</view>
		<view class="address-" v-show="nowindex==2">
			<view class="bold-t">
				最多可以提币<text class="btn-amount">
					{{dataObj.balance}}{{dataObj.name=='USDT'?'USD':dataObj.name}}
				</text>   
			</view>
			
			
		</view>
		<view class="chongzhi-wrap" v-if="nowindex==1">
			<view class="title">
				向如下地址汇入{{type}}完成充值
			</view>
			<view class="img-erweima">
				   <tki-qrcode
				   
				    ref="qrcode"
				    
				    :val="val"
				    :size="size"
				    :unit="unit"
				    :background="background"
				    :foreground="foreground"
				    :pdground="pdground"
				    :onval="onval"
				    :loadMake="loadMake"
				   
				    :showLoading="true"
				    
				     />

			</view>
			<view class="address-wenzi">
				{{dataObj.charge_address}}
			</view>
			<view class="copy-wrap" @click="copy">
				<text> 复制地址</text>
				<image src="./copy.png"></image>
				
			</view>
		</view>
		<view class="tip">
			
			
			<view class="item-line" v-for="(item,index) in instruction" :key="index">
				
				{{item}}
				
			
			</view>
		</view>
		<view class="subdata" @click="topay" v-if="nowindex==2">
			提币
		</view>
		<paypass ref="yspay"  @submit="submitpay"></paypass>
	</view>
</template>

<script>
	import paypass from "@/components/ys-paypass/ys-paypass.vue";
	import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"
	export default {
		components:{
			paypass,
			tkiQrcode
		},
		data() {
			return {
				instruction:[],
				isdata:{},
				remark:'',
				ifShow: true,
				val: '', // 要生成的二维码值
				size: 488, // 二维码大小
				unit: 'rpx', // 单位
				background: '#fff', // 背景色
				foreground: '#000', // 前景色
				pdground: '#000', // 角标色
				icon: '', // 二维码图标
				iconsize: 40, // 二维码图标大小
				lv: 3, // 二维码容错级别 ， 一般不用设置，默认就行
				onval: true, // val值变化时自动重新生成二维码
				loadMake: true, // 组件加载完成后自动生成二维码
				src: '', // 二维码生成后的图片地址或base64,
				nowindex:1,
				amount:'',
				address:'',
				type:'',
				dataObj:{}
			}
		},
		onShow(){
			//this.getData()
		},
		onLoad(options) {
			this.type=options.type=='USDT'?'USD':options.type
			uni.setNavigationBarTitle({
			    title: options.type=='USDT'?'USD':options.type
			});
			this.panduan()
			//this.getData()
		},
		onNavigationBarButtonTap:function(e){
			
			let type=this.type=='USD'?'USDT':this.type
			uni.navigateTo({
				url: `../bizhongmingxi/index?type=${type}`
			});
		               
		 },
		methods: {
			panduan(){
				let that=this
				
				that.apipost('/api/assets/hy_details').then(res => {
					if(res.Code==10200){
						
						let data=res.Data?res.Data:{}
						that.dataObj=res.Data?res.Data:{}
						that.val=that.dataObj.charge_address
						that.isdata=res.Data
						if(!that.isdata.extract_hidden&&that.isdata.charge_hidden){
							that.nowindex=2
						}
						if(!that.isdata.charge_hidden&&that.isdata.extract_hidden){
							that.nowindex=1
						}
						if(!that.isdata.charge_hidden&&!that.isdata.extract_hidden){
							that.nowindex=1
						}
						that.instruction=res.Data.instruction
						console.log(res.Data)
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			erweima(){
				
				let that=this
				uni.scanCode({
				    success: function (res) {
						that.address=res.result
				  },fail:function(){
					  // uni.showToast({
					  //     title: '请设置软件相机权限',
					  //     duration: 2000,
					  // 	icon:'none'
					  // });
				  }
				});
			},
			getAll(){
				
				
				this.amount=this.dataObj.balance
			},
			topay(){
				
				if(this.address==''){
					uni.showToast({
					    title: '输入提币地址',
					    dduration:4000,
						icon:'none'
					});
					return
				}
				
				this.$refs.yspay.show();
			},
			submitpay(ex){
				this.subData(ex.value)
			},
			subData(pwd){
				let that=this
				uni.showModal({
				    title: '确认提交？',
				    content: '',
				    success: function (res) {
				        if (res.confirm) {
				            that.apipost('/api/assets/extract',{
								address:that.address,
								amount:that.amount,
								pwd,
				            	currency:that.type
				            },true).then(res => {
				            	if(res.Code==10200){
									uni.showToast({
										title: res.Message,
										duration:4000,
										icon: 'none'
									});
									uni.navigateBack()
				            		// let data=res.Data?res.Data:{}
				            		// that.dataObj=res.Data?res.Data:{}
				            		// that.src=that.dataObj.charge_address
				            	}
				            	
				            }).catch(err=>{
				            	console.log(err)
				            });
				        } else if (res.cancel) {
				            
				        }
				    }
				});
			},
			copy(){
				
				let that=this
				uni.setClipboardData({
					data: that.dataObj.charge_address, //要被复制的内容
					success: function() {
						
						uni.showToast({
							title: '复制成功',
							duration:4000,
							icon: 'none'
						});
					},
					fail: function(err) {
						
						uni.showToast({
							title: '复制失败',
							duration:4000,
							icon: 'none'
						});
					}
			});
			},
			tabChange(type){
				let that=this
				
				this.nowindex=type
			},
			getData(){
				let that=this
				
				that.apipost('/api/assets/currency_details',{
					currency:that.type=='USD'?'USDT':that.type
				},true).then(res => {
					if(res.Code==10200){
						let data=res.Data?res.Data:{}
						that.dataObj=res.Data?res.Data:{}
						that.val=that.dataObj.charge_address
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			tabClick(val){
				this.nowindex=val
				this.nowdata=this.dataObj[val-1]
			},
			enterpage(path){
				if(path){
					uni.navigateTo({
					    url: path
					});
				}else{
					uni.showToast({
					    title: '暂未开放',
					    duration:4000,
						icon:'none'
					});
				}
			}
		}
	}
</script>

<style>
	.subdata{
		width:616rpx;
		height:90rpx;
		display:flex;
		align-items: center;
		justify-content: center;
		color:#fff;
		background:#007aff;
		border-radius:10rpx;
		margin:30rpx auto;
	}
	.copy-wrap uni-image{
		width:44rpx;
		height:44rpx;
	}
	.copy-wrap{
		display:flex;
		align-items: center;
		width:100px;
		margin:0 auto;
		color:#b3b3b3;
	}
	.address-wenzi{
		color:#7d7d7f;
		font-size:26rpx;
		text-align:center;
	}
	.chongzhi-wrap .img-erweima{
		display:flex;
		justify-content: center;
		align-items: center;
		width:488rpx;
		height:488rpx;
		margin:0 auto;
		margin-top:16rpx;
		margin-bottom:16rpx;
	}
	.chongzhi-wrap .title{
		color:#7d7d7f;
		text-align:center;
	}
	.tip .item-line{
		padding-top:8rpx;
	}
	.address .bold-t{
		padding-top:10rpx;
		font-size:28rpx;
		color:#515151;
	}
	.address .btn-amount{
		width:190rpx;
		color:#fe6700;
	}
	.address .btn{
		height:40rpx;
		width:40rpx;
		background:url(../../static/copybtn.png) no-repeat;
		background-size:100% 100%;
	}
	.ipt-wrap{
		flex:1;
		display:flex;
		justify-content: space-between;
	}
	.tip{
		width:600rpx;
		margin:0 auto;
		color:#86858a;
		margin-top:46rpx;
	}
	.address{
		width:600rpx;
		margin:0 auto;
		border-bottom:1rpx solid #e7e7e9;
	}
	.address-{
		width:600rpx;
		margin:0 auto;
		margin-top:8rpx;
		
	}
	.address- .btn-amount{
		
		color:#fe6700;
	}
	.address .ipt-wrap{
		height:82rpx;
		display:flex;
		align-items: center;
	}
	.address .title{
		padding:26rpx 0 8rpx 0;
		font-size:34rpx;
	}
	.tab-wrap .item{
		color:#747476;
		height:100%;
		display:flex;
		box-sizing: border-box;
		align-items: center;
		justify-content: center;
		border-bottom:5rpx solid #fff;
	}
	.tab-wrap .active{
		color:#000;
		border-bottom:4rpx solid #1c74d6;
	}
	.tab-wrap{
		width:740rpx;
		margin:0 auto;
		margin-top:16rpx;
		margin-bottom:48rpx;
		border-bottom:1rpx solid #dfdfdf;
		height:112rpx;
		display:flex;
		justify-content: space-around;
		align-items: center;
	}
	page{
		background:#fff;
		border-top:1rpx solid #e6e6e6;
	}
	.banner{
		color:#fff;
		
		width:692rpx;
		height:180rpx;
		position:relative;
		margin:0 auto;
		border-radius:8rpx;
	}
	.banner .title{
		position:absolute;
		top:40rpx;
		left:42rpx;
		
	}
	.banner .number{
		font-size:38rpx;
		position:absolute;
		top:90rpx;
		left:42rpx;
	}
	.wrap{
		padding:24rpx 0;
	}
	.ipt-wrap input{
		flex:1;
		font-size:26rpx;
	}
</style>
